<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Dell
  Date: 2018/12/19
  Time: 17:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>新增管理员信息</title>
    <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css"  media="all">
    <script language="javascript" type="text/javascript" src="My97DatePicker/WdatePicker.js"></script>
</head>
<body margintop="100px">



<form id="adminForm" name="adminForm" class="layui-form" action="" method="post">


    <div class="layui-form-item">
        <label class="layui-form-label">账户</label>
        <div class="layui-input-inline">
            <input type="text" name="account" lay-verify="account" autocomplete="off" placeholder="" class="layui-input layui-form-danger" value="">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-inline">
            <input type="password" name="password" lay-verify="password" autocomplete="off" placeholder="" class="layui-input layui-form-danger" value="">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-inline">
            <input type="text" name="name" lay-verify="name" autocomplete="off" placeholder="" class="layui-input layui-form-danger" value="">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-inline">
            <select name="sex">
                <option value=""></option>

                <option value="1">男</option>
                <option value="0">女</option>
            </select>
            <div class="layui-unselect layui-form-select">

                <dl class="layui-anim layui-anim-upbit" style="">
                    <dd lay-value="" class="layui-select-tips">请选择</dd>
                </dl>
            </div>
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">头像URL</label>
        <div class="layui-input-inline">
            <input type="text" name="img" lay-verify="img" autocomplete="off" placeholder="" class="layui-input layui-form-danger" value="">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">手机号</label>
        <div class="layui-input-inline">
            <input type="text" name="phone" lay-verify="phone" autocomplete="off" placeholder="" class="layui-input layui-form-danger" value="">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-inline">
            <input type="text" name="email" lay-verify="email" autocomplete="off" placeholder="" class="layui-input layui-form-danger" value="">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">角色</label>
        <div class="layui-input-inline">
            <select name="role" lay-filter="aihao">
                <option value=""></option>

                <c:forEach var="l" items="${requestScope.roles}">
                    <option value="${l.roId}">${l.roName}</option>
                </c:forEach>

            </select><div class="layui-unselect layui-form-select">

        </div>
        </div>
    </div>


    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">描述</label>
        <div class="layui-input-block">
            <textarea name="desc" lay-verify="desc" placeholder="请输入内容" class="layui-textarea"></textarea>
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">加入时间</label>
        <div class="layui-input-inline">
            <input type="text" name="time" lay-verify="time" autocomplete="off" placeholder="" class="layui-input layui-form-danger" value="" onClick="WdatePicker({el:this,dateFmt:'yyyy-MM-dd HH:mm:ss'})">
        </div>
    </div>



    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="demo1">添加</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>



</form>



</body>
<script src="../../js/jquery.min.3.1.0.js"></script>
<script src="../../layuiadmin/layui/layui.js" charset="utf-8"></script>

<script>
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;

        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });

        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');

        //自定义验证规则
        form.verify({
            account: function(value){
                if(value.length < 3){
                    return '标题至少得3个字符啊';
                }
            }
            ,name: [
                /^[\u4e00-\u9fa5]{2,}$/
                ,'姓名必须为2位以上的中文字符'
            ]

            ,password: [
                /^[\S]{6,12}$/
                ,'密码必须6到12位，且不能出现空格'
            ]
            ,phone:[
                /^0?(13|14|15|17|18|19)[0-9]{9}$/
                ,'请输入正确的手机号码'
            ]
            ,email:[
                /^\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}$/
                ,'请输入正确的邮箱地址'
            ]
            ,time:function (value) {
                if(value==""){
                    return '时间不能为空！';
                }
            }
            ,img:function (value) {
                if(value==""){
                    return '头像URL不能为空！';
                }
            }

        });

        //监听指定开关
        form.on('switch(switchTest)', function(data){
            layer.msg('开关checked：'+ (this.checked ? 'true' : 'false'), {
                offset: '6px'
            });
            layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        });

        //监听提交
        form.on('submit(demo1)', function(data){
            var index = parent.layer.getFrameIndex(window.name);

            $.ajax({
                url:"/AdminAddServlet",   //请求路径
                datatype:"json",//返回的格式
                data:$("#adminForm").serialize(), //参数
                type:"post", //什么请求
                success:function (data) { //请求成功以后
                    //AJAX成功以后返回的
                    var obj = eval('(' + data + ')');
                    layer.msg(obj.state);

                    //延时500ms关闭窗口
                    setTimeout(function () {
                        parent.layer.close(index);
                    }, 500);
                }
            });


            return false;
        });




    });
</script>
</html>
